package gui.utilitaries;

import gui.RecomendationWindow;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class ProductFieldKeyListener implements KeyListener {

	private boolean k_ctrl,k_space,k_enter;
	public RecomendationWindow parentRecomWindow;
	
	
	public ProductFieldKeyListener(RecomendationWindow parentRecomWindow) {
		super();
		this.k_ctrl = false;
		this.k_space = false;
		this.k_enter = false;
		this.parentRecomWindow = parentRecomWindow;
	}

	@Override
	public void keyTyped(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public void keyReleased(KeyEvent e) {
		//If the key released was the Ctrl key 
		if(e.getKeyCode()==KeyEvent.VK_CONTROL)
			this.k_ctrl=false;
		//If the key released was the Space key
		if(e.getKeyCode()==KeyEvent.VK_SPACE)
			this.k_space=false;
		//If the key released was the Enter key
		if(e.getKeyCode()==KeyEvent.VK_ENTER)
			this.k_enter=false;
	}
	
	@Override
	public void keyPressed(KeyEvent e) {
		//If the key released was the Ctrl key 
		if(e.getKeyCode()==KeyEvent.VK_CONTROL)
			this.k_ctrl=true;
		//If the key released was the Space key
		if(e.getKeyCode()==KeyEvent.VK_SPACE)
			this.k_space=true;
		//If the key released was the Enter key
		if(e.getKeyCode()==KeyEvent.VK_ENTER)
			this.k_enter=true;
		if(this.k_ctrl&&this.k_enter&&this.k_space)
			this.parentRecomWindow.openAutoCompleteFrame(this.parentRecomWindow.getTextFieldProduct().getText());
	}

}
